package com.iuie.ns.datum.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iuie.ns.datum.service.IDevProjectService;
import com.iuie.ns.datum.vo.DevProjectVO;
import com.iuie.ns.frame.web.dataset.vo.Page;
import com.iuie.ns.frame.web.response.vo.ResponseInfo;

/**
 * 项目管理
 * @author liujie
 * @date 2018-02-03 17:17:00
 */
@RequestMapping("datum/devProj")
@Controller
public class DevProjectController {
	
	@Resource
	private IDevProjectService projectService;

	/**
	 * 项目管理index
	 * @param request
	 * @return
	 * @date 2018-02-03 17:17:10
	 */
	@RequestMapping
	public String index(HttpServletRequest request){
		return "view-datum/development/devProject";
	}
	
	/**
	 * 新增项目
	 * @param request
	 * @return
	 */
	@RequestMapping("add/index")
	public String addOneIndex(HttpServletRequest request){
		return "view-datum/development/devProjectAdd";
	}
	
	/**
	 * 修改项目
	 * @param request
	 * @param id
	 * @return
	 */
	@RequestMapping("update/{id}/index")
	public String updateOneIndex(@PathVariable("id") Long id, HttpServletRequest request){
		request.setAttribute("id", id);
		return "view-datum/development/devProjectAdd";
	}
	
	/**
	 * 根据ID查询
	 * @param id
	 * @return
	 */
	@RequestMapping("find/id/{id}")
    @ResponseBody
	public ResponseInfo findById(@PathVariable("id") Long id) {
		return ResponseInfo.successInfoByObject(projectService.findById(id));
	}
	
	/**
	 * 根据条件分页查询
	 * @param page
	 * @param condition
	 */
	@RequestMapping("find/page")
    @ResponseBody
	public ResponseInfo findByPage(Page page, DevProjectVO condition) {
		List<DevProjectVO> list = projectService.findByPage(page, condition);
		return ResponseInfo.successInfo(list, page);
	}
	
	/**
	 * 查询所有项目
	 */
	@RequestMapping("find/all")
    @ResponseBody
	public ResponseInfo findAll() {
		return ResponseInfo.successInfoByObject(projectService.findAll());
	}
	
	/**
	 * 根据ID删除
	 * @param id
	 * @return
	 */
	@RequestMapping("delete/id/{id}")
    @ResponseBody
	public ResponseInfo deleteById(@PathVariable("id") Long id) {
		projectService.deleteById(id);
		return ResponseInfo.successInfo("删除成功！");
	}
	
	/**
	 * 单条保存
	 * @param proj
	 * @return
	 */
	@RequestMapping("save/one")
    @ResponseBody
	public ResponseInfo saveOne(DevProjectVO proj) {
		projectService.saveOne(proj);
		return ResponseInfo.successInfo("保存成功！");
	}
	
	/**
	 * 导出项目的所有表信息
	 * @param projectId
	 * @throws IOException 
	 * @date 2018年5月13日下午3:31:24
	 */
	@RequestMapping("export/{projectId}/tables")
	public void exportProjectTables(@PathVariable("projectId") Long projectId, HttpServletRequest request, 
			HttpServletResponse response) throws IOException {
		projectService.exportProjectTables(projectId, response);
	}
}
